package com.ipartek.pruebas.dao;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;

import com.ipartek.pruebas.bean.Alumno;
import com.ipartek.pruebas.bean.Curso;
import com.ipartek.pruebas.excepciones.AlumnoException;

public class CursoOBDCDAO implements CursoDAO{
	
	Connection con;
	PreparedStatement ptmt = null;
	ResultSet result = null;
	
	 private final static String TABLE_NAME     = "CURSO";
	//Columnas
	 private final static String  COL_ID             = "id";
	 private final static String  COL_DESCRIPCION    = "nombre";
	 private final static String  COL_MAX_ALUMNOS 	 = "maxalumnos";
	 
	
	public CursoOBDCDAO(){
		
	}
	
	public List<Curso> getCursos(){
		List<Curso> list = new ArrayList<Curso>();
		
		con = OBDCDAOFactory.getConnection();
		String sql = "SELECT * FROM " +  TABLE_NAME;
		try{
		ptmt = con.prepareStatement(sql);
		result = ptmt.executeQuery();
		while(result.next()){
			Curso c = new Curso();
			c.setid(result.getString( COL_DESCRIPCION));
			c.setDescripcion(result.getString( COL_DESCRIPCION));
			c.setMaxAlumnos(result.getInt( COL_MAX_ALUMNOS));
			list.add(c);
			
		}
		}catch (SQLException e) {
			e.printStackTrace();
		}
		
		return list;
	}

	@Override
	public boolean udapteCurso(Curso curso) throws AlumnoException {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public Alumno getCursoByID(String IDCurso) throws AlumnoException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean deleteCurso(String dni) throws AlumnoException {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean insertCurso(Curso curso) throws AlumnoException {
		// TODO Auto-generated method stub
		return false;
	}
}
